package com.admin.service.impl;

import com.admin.entity.StationType;
import com.admin.mapper.StationTypeMapper;
import com.admin.service.IStationTypeService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Map;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author marisheng
 * @since 2019-11-21
 */
@SuppressWarnings("ALL")
@Service
public class StationTypeServiceImpl extends ServiceImpl<StationTypeMapper, StationType> implements IStationTypeService {
    @Autowired
    private StationTypeMapper stationTypeMapper;

    /**
     * 分页查询站点类型，及模糊查询
     * @param page
     * @param limit
     * @param
     * @return
     */

     @Override
    public IPage FYcha(int page, int limit, String stationType) {
        Page p = new Page(page,limit);
        QueryWrapper q = new QueryWrapper();
        if (stationType!=null && stationType!="")
        {
            q.like("station_type_name",stationType);
        }
        IPage iPage = stationTypeMapper.selectPage(p,q);
        return iPage;
    }

    /**
     * 插入站点类型前查数据库类型是否重复
     * @return
     */
    @Override
    public StationType selectAndAddType(StationType stationType){
        QueryWrapper q=new QueryWrapper();
        q.eq("station_type_name",stationType.getStationTypeName());
        StationType s=stationTypeMapper.selectOne(q);
        return s;
    }

    /**
     * 编辑站点前判断站点名字是否重复
     * @return
     */
    @Override
    public StationType editAddSelect(StationType stationType){
        QueryWrapper q=new QueryWrapper();
        q.eq("station_type_name",stationType.getStationTypeName());
        q.ne("station_type_id",stationType.getStationTypeId());
        return stationTypeMapper.selectOne(q);
    }

    /**
     * 主题管理分页查询所有记录  根据名称查询
     * @param map  主题名称
     * @param page
     * @param limit
     * @return
     */
    @Override
    public IPage zhuTiFindALL(int page, int limit, Map map) {
        Page p = new Page(page, limit);
        IPage iPage = stationTypeMapper.zhuTiFindAll(p,map);
        return iPage;
    }

}
